/** * This program peforms multiplication of two matrices entered by the user. * The main method asks for the user to enter two matrices, and then calls * multMatrices() to do the multiplication. The result matrix is then * printed. */ class Product { public static void main (String[] args) { // DECLARE VARIABLES/DATA DICTIONARY int[][] a; // GIVEN: A matrix of integers int[][] b; // GIVEN: A matrix of integers int aRows; // GIVEN: Number of rows in a. int aCols; // GIVEN: Number of columns in a. int bRows; // GIVEN: Number of rows in b. int bCols; // GIVEN: Number of columns in b. int[][] c; // RESULT: Product of a and b // PRINT OUT IDENTIFICATION INFORMATION System.out.println(); System.out.println("ITI 1120 Fall 2006, Lab 10, Example 3"); System.out.println("Name: Diana Inkpen, Student# 123456"); System.out.println(); // READ IN GIVENS System.out.println( "Enter the number of rows in matrix A: " ); aRows = ITI1120.readInt( ); System.out.println( "Enter the number of columns in matrix A: " ); aCols = ITI1120.readInt( ); a = MatrixLib.readIntMatrix( aRows, aCols ); System.out.println( "Enter the number of rows in matrix B: " ); bRows = ITI1120.readInt( ); System.out.println( "Enter the number of columns in matrix B: " ); bCols = ITI1120.readInt( ); b = MatrixLib.readIntMatrix( bRows, bCols ); // BODY OF ALGORITHM c = multMatrices( a, b ); // PRINT OUT RESULTS AND MODIFIEDS System.out.println( ); System.out.println( "The product matrix C is: " ); System.out.println( ); MatrixLib.printMatrix( c ); } // If the 'main' method calls other algorithms, put the method(s) below. /** * Performs matrix multiplication on matrices a and b, returning c. * * Matrices a and b are assumed to be rectangular, where a is m x n, and * b is n x p, for integers m, n, and p. The resulting matrix c will * be m x p. The dimensions are not passed as parameters; instead, * the dimensions are determined from the array lengths. * * GIVENS: a: an m x n matrix containing integers * b: an n x p matrix containing integers * To be completed */ public static int[][] multMatrices( int[][] a, int[][] b ) { // DECLARE VARIABLES / DATA DICTIONARY // BODY OF ALGORITHM // RETURN RESULT } }